package com.atao.baokede.controller;

import com.atao.baokede.pojo.Result;
import com.atao.baokede.pojo.vo.ItemOrderVo;
import com.atao.baokede.service.ItemOrderService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 商品订单层
 */
@RestController
@RequestMapping("/itemOrder")
public class ItemOrderController {

    @Autowired
    private ItemOrderService itemOrderService;
    /**
     * 添加商品订单
     *
     * @param itemId 商品id
     * @param num 购买数量
     * @param addressId 收货地址id
     * @param spec 商品规格(Json格式)
     * @return 无
     */
    @PostMapping("/addItemOrder")
    public Result<ItemOrderVo> addChargeOrder(@RequestParam Long itemId,
                                              @RequestParam Long num,
                                              @RequestParam Long addressId,
                                              @RequestParam String spec){
        return Result.success(itemOrderService.addOrder(itemId,num,addressId,spec));
    }

    /**
     * 添加购物车订单
     * @param ids 购物车id集合
     * @return
     */
    @PostMapping("/addCartOrder")
    public Result<ItemOrderVo> addCartOrder(@RequestBody List<Long> ids,
                               @RequestParam Long addressId){
        return Result.success(itemOrderService.addCartOrder(ids,addressId));
    }
}
